<?php

/*
 * litchicms
 * Copyright (C) 2010-5-24 Author: tiefa(539247@qq.com)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
!defined('BRK') && exit("!");

ob_header_char("utf-8");

$ay_cache_dir = SYSTEM . 'cache/ay_cache';
check_make_dir($ay_cache_dir);

$cachefile = $ay_cache_dir . '/' . implode('', $RT['v']);

/*
 * 静默更新 .前台AJAX请求更新. 后期实现
 */


//如果存在 别且文件信息正确
if (is_file($cachefile . '.php') && is_file($cachefile . '_info.php')) {
    require $cachefile . '_info.php';
    if ($cache_info['cache_datetime'] + $BRK_SET['cachetime'] > $BRK_GLOBAL['datearray'][0]) {
        require $cachefile . '.php';
        return;
    }
}

//如果不存在, 或者文件信息不正确
ob_start();
require 'cachemode/nocache.inc.php';
$cache_contents = ob_get_contents();
$infoarr = array(
    'cache_datetime' => $BRK_GLOBAL['datearray'][0],
);
$infostr = "<?php\n!defined('BRK') && exit(\"!\");\n";
$infostr.="\$cache_info=" . var2string($infoarr) . ";";
file_put_contents($cachefile . '_info.php', $infostr);
file_put_contents($cachefile . '.php', $cache_contents);
ob_flush();

//如果不存在, 或者文件信息不正确
//}else(不存在){
//    判断编译后的模板文件
//    if(不存在){
//        编译模板
//    }
//  require 'nocache.inc';
//     include $BRK_GLOBAL['tempfile'];
//   生成缓存 (尾部加JS,htmltime---用于计算是否该更新,用JS请求更新)
//   输出
//}





